package it.valeandre.omino.adapter;

import it.valeandre.omino.MatchDetailsActivity;
import it.valeandre.omino.fragment.BaseFragment;
import it.valeandre.omino.fragment.MatchFormationPageFragment;
import it.valeandre.omino.fragment.MatchStatisticsPageFragment;
import it.valeandre.omino.fragment.MatchTimelinePageFragment;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.MotionEvent;

public class MatchDetailsSlidePagerAdapter extends FragmentStatePagerAdapter {
	
	public static final int NUM_PAGES = 4;
    private Bundle mMatchData;
    private MatchDetailsActivity mActivity;
    private BaseFragment.OnFragmentTouchListener mTouchListener = new BaseFragment.OnFragmentTouchListener() {
        public void onFragmentTouch(MotionEvent event) {
            mActivity.showArrowPanelForAWhile();
        }
    };

	public MatchDetailsSlidePagerAdapter(FragmentManager fm, MatchDetailsActivity activity, Bundle matchData) {
		super(fm);
        mActivity = activity;
        mMatchData = matchData;
	}

	@Override
	public Fragment getItem(int position) {
        switch (position) {
            case 0:
                return MatchTimelinePageFragment.newInstance(mMatchData, mTouchListener);
            case 1:
                return MatchStatisticsPageFragment.newInstance(mMatchData, mTouchListener);
            case 2:
                return MatchFormationPageFragment.newInstance(mMatchData, MatchFormationPageFragment.HOME_FORMATION, mTouchListener);
            case 3:
                return MatchFormationPageFragment.newInstance(mMatchData, MatchFormationPageFragment.AWAY_FORMATION, mTouchListener);
            default:
                return MatchStatisticsPageFragment.newInstance(mMatchData);
        }
	}

	@Override
	public int getCount() {
		return NUM_PAGES;
	}

}
